import React, { useEffect, useState } from 'react'
import { getRecommendProFn } from '../../api/pro'

import { Table, Image, Tag, Switch, Input, Button } from 'antd'




export default function Index() {

    const [recommend, setrecommend] = useState([])

    useEffect(() => {
        getRecommendProFn({
            type: 'isrecommend',
            flag: 1
        }).then(res => {
            setrecommend(res.data)
        })
    }, [])


    const [current, setcurrent] = useState(1)
    const columns = [{
        title: '序号',
        render(t, r, i) {
            return <Tag>{(current - 1) * 10 + i + 1}</Tag>
        },
        width: 80
    }, {
        title: '商品名称',
        dataIndex: 'proname',
        width: 300
    }, {
        title: '商品图片',
        dataIndex: 'img1',
        width: 150,
        render(t) {
            return <Image src={t} width={80} />
        }
    }, {
        title: '商品分类',
        dataIndex: 'category',
    }, {
        title: '商品价格',
        dataIndex: 'originprice',
        sorter: (a, b) => a.originprice - b.originprice,
    }, {
        title: '商品折扣',
        dataIndex: 'discount',
        sorter: (a, b) => a.discount - b.discount,
    }, {
        title: '是否推荐',
        dataIndex: 'isrecommend',
        render(t) {
            return <Switch defaultChecked={t} />
        }
    }, {
        title: '是否售卖',
        dataIndex: 'issale',
        render(t) {
            return <Switch defaultChecked={t} />
        }
    }, {
        title: '是否秒杀',
        dataIndex: 'isseckill',
        render(t) {
            return <Switch defaultChecked={t} />
        }
    }
    ]



    return (
        <div>
            <h3>推荐列表</h3>
            <Table
                rowKey={'proid'}
                dataSource={recommend}
                pagination={{
                    current,
                    onChange(page) {
                        setcurrent(page)
                    }
                }}
                columns={columns}
                scroll={{
                    y: 450
                }}
                locale={{
                    triggerDesc: '点击降序',
                    triggerAsc: '点击升序',
                    cancelSort: '取消排序',
                    filterConfirm: '确定',
                    filterReset: '重置',
                }}
            />
        </div>
    )
}
